package com.luom.fsp.controller;

import com.luom.fsp.common.BaseResponse;
import com.luom.fsp.common.ResultUtils;
import com.luom.fsp.service.OrderStatsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

@RestController
@RequestMapping("/order/stats")
@Slf4j
public class OrderStatsController {

    @Resource
    private OrderStatsService orderStatsService;

    
    /**
     * 获取近N日每日订单数
     * @param days 天数，默认为7天
     */
    @GetMapping("/daily")
    public BaseResponse<Map<String, String>> getLastNDaysOrderCount(@RequestParam(defaultValue = "7") Integer days) {
        if (days > 30){
            throw new RuntimeException("天数不能超过30天");
        }
        Map<String, String> data = orderStatsService.getLastNDaysOrderCount(days);
        return ResultUtils.success(data);
    }
}
